// SI_BPA.cpp: implementation of the CSI_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SI_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSI_BPA::CSI_BPA()
{
	m_chType = 'S';
	m_chSubType = 'I';
	m_chChangeCode = ' ';

	m_dTrw = 0;
	m_dT5 = 0;
	m_dT6 = 0;
	m_dT7 = 0;
	m_dKr = 0;
	m_dTrp = 0;
	m_dTw = 0;
	m_dTw1 = 0;
	m_dTw2 = 0;
	m_dKs = 0;
	m_dT9 = 0;
	m_dT10 = 0;
	m_dT12 = 0;
	m_chINP = '0';

	m_strCardType[0] = 'S';
}

CSI_BPA::CSI_BPA(CSI_BPA &siBPA):CUnit_BPA(siBPA)
{
	m_dTrw = siBPA.m_dTrw;
	m_dT5 = siBPA.m_dT5;
	m_dT6 = siBPA.m_dT6;
	m_dT7 = siBPA.m_dT7;
	m_dKr = siBPA.m_dKr;
	m_dTrp = siBPA.m_dTrp;
	m_dTw = siBPA.m_dTw;
	m_dTw1 = siBPA.m_dTw1;
	m_dTw2 = siBPA.m_dTw2;
	m_dKs = siBPA.m_dKs;
	m_dT9 = siBPA.m_dT9;
	m_dT10 = siBPA.m_dT10;
	m_dT12 = siBPA.m_dT12;
	m_chINP = siBPA.m_chINP;
}

CSI_BPA::~CSI_BPA()
{

}

bool CSI_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSI_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dTrw = StrToDouble(&buffer[16],4,4);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dT5 = StrToDouble(&buffer[20],5,3);
	if(EndOfSec(&buffer[20],5))
		return true;

	m_dT6 = StrToDouble(&buffer[25],5,3);
	if(EndOfSec(&buffer[25],5))
		return true;

	m_dT7 = StrToDouble(&buffer[30],5,3);
	if(EndOfSec(&buffer[30],5))
		return true;

	m_dKr = StrToDouble(&buffer[35],6,4);
	if(EndOfSec(&buffer[35],5))
		return true;

	m_dTrp = StrToDouble(&buffer[41],4,4);
	if(EndOfSec(&buffer[41],5))
		return true;

	m_dTw = StrToDouble(&buffer[45],5,3);
	if(EndOfSec(&buffer[45],5))
		return true;

	m_dTw1 = StrToDouble(&buffer[50],5,3);
	if(EndOfSec(&buffer[50],5))
		return true;

	m_dTw2 = StrToDouble(&buffer[55],5,3);
	if(EndOfSec(&buffer[55],5))
		return true;

	m_dKs = StrToDouble(&buffer[60],4,2);
	if(EndOfSec(&buffer[60],5))
		return true;

	m_dT9 = StrToDouble(&buffer[64],5,3);
	if(EndOfSec(&buffer[64],5))
		return true;

	m_dT10 = StrToDouble(&buffer[69],5,3);
	if(EndOfSec(&buffer[69],5))
		return true;

	m_dT12 = StrToDouble(&buffer[74],5,3);
	if(EndOfSec(&buffer[74],5))
		return true;

	m_chINP = buffer[79];
	if(EndOfSec(&buffer[79],1))
		return true;

	return true;
}

bool CSI_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSI_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dTrw,&buffer[16],4,4);
	DoubleToStr(m_dT5,&buffer[20],5,3);
	DoubleToStr(m_dT6,&buffer[25],5,3);
	DoubleToStr(m_dT7,&buffer[30],5,3);
	DoubleToStr(m_dKr,&buffer[35],6,4);
	DoubleToStr(m_dTrp,&buffer[41],4,4);
	DoubleToStr(m_dTw,&buffer[45],5,3);
	DoubleToStr(m_dTw1,&buffer[50],5,3);
	DoubleToStr(m_dTw2,&buffer[55],5,3);
	DoubleToStr(m_dKs,&buffer[60],4,2);
	DoubleToStr(m_dT9,&buffer[64],5,3);
	DoubleToStr(m_dT10,&buffer[69],5,3);
	DoubleToStr(m_dT12,&buffer[74],5,3);
	buffer[79] = m_chINP; 

	return true;
}